﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebService.BUS;
using WebService.DAO;
using WebService.VO;
using System.Text;
using System.Data;

namespace WebService.Admin
{
    public partial class ListPlaces : System.Web.UI.Page
    {
        DataTable dt;
        DataTable dt2;
        protected void Page_Load(object sender, EventArgs e)
        {
            dt = new DataTable();
            dt2 = new DataTable();
        }

        protected void btn_getdata_Click(object sender, EventArgs e)
        {
            string location = txt_lat.Text.ToString().Trim() + "," + txt_lng.Text.ToString().Trim();
            string type = GooglePlaces.types[ddl_type.SelectedIndex];
            int keyid = ddl_key.SelectedIndex;
             dt = GooglePlaces.parse2dt(location, type, keyid, "vi", Convert.ToInt32(ddl_radius.SelectedValue));
            if (dt == null)
            {
                txt_success.Text = "Key invalid";
                return;
            }
            txt_row.Text = dt.Rows.Count.ToString();
            Session["DataSet"] = dt;
            GridView1.DataSource = dt;
            GridView1.DataBind();
            
            btn_update.Visible = true;
            txt_success.Text = "";
        }

        protected void btn_update_Click(object sender, EventArgs e)
        {
            ItemBUS itemBUS = new ItemBUS();
            if (Session["DataSet"] != null)
            {
                dt2 = (DataTable)Session["DataSet"];
            }
            if (dt2 != null)
            {
                int i = itemBUS.insertFromTbl(dt2, ddl_type.SelectedIndex + 1);
                txt_success.Text = i + "rows";
            }
            else
            {
                txt_success.Text = "d2 null";
            }
            btn_update.Visible = false;
        }
    }
}